/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.inscrito;

import DBMS.DataBaseManager;
import clases.Inscripcion;
import clases.Preinscrito;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import java.lang.reflect.Field;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

/**
 *
 * @author andreth
 */
public class Inscribirse extends DispatchAction {

    private final String PAGE = "page";
    private final String SUCCESS = "success";
    private final String FAILURE = "failure";

    public ActionForward populate(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        DataBaseManager dbms = DataBaseManager.getInstance();
        Preinscrito p = new Preinscrito();
        p.setCedula((String) request.getSession().getAttribute("cedula")); 
        Inscripcion planilla = dbms.consultarPlanillaInscripcion(p);
        request.setAttribute("Inscripcion", planilla);
        return mapping.findForward(PAGE);
    }

    public ActionForward save(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Inscripcion planilla = (Inscripcion) form;
        planilla.escapar();
        System.out.println("ENTRANDO A GUARDAR LA MEGA PLANILLA");
        if (planilla.valida()) {
            DataBaseManager dbms = DataBaseManager.getInstance();
            dbms.agregarPlanillaInscripcion(planilla);
            return mapping.findForward(SUCCESS);
        } else {
            request.setAttribute("Inscripcion", planilla);
            return mapping.findForward(FAILURE);
        }
    }
}
